﻿using System;
using System.Diagnostics;
using System.Data;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using ConsoleApp1.Others;
using ConsoleApp1.Requests;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            #region IP有效性测试

            do
            {
                IpInfoRequest ipInfoRequest = new IpInfoRequest();
                string result = ipInfoRequest.MakeRequests(false);
                Console.WriteLine(result);
                System.Threading.Thread.Sleep(3 * 1000);
            } while (true);

            #endregion

            #region 校正Cookie是否有效
            //int i = 0;
            //WebCookiePhone webCookiePhone = Newtonsoft.Json.JsonConvert.DeserializeObject<WebCookiePhone>(File.ReadAllText("WebCookiePhone.json"));
            //foreach (var item in webCookiePhone.RECORDS)
            //{
            //    Console.WriteLine(++i);
            //    Requests.CheckWebCookie.MakeRequests(item.WebCookie, item.Phone);
            //}

            #endregion

            #region 菜单选择
            //Console.WriteLine("\n\n\n");
            //Console.WriteLine("\t1.菜单1");
            //Console.WriteLine("\t1.菜单2");
            //Console.WriteLine("\t1.菜单3");
            //int o = CP.CPwrite(4, 0, 3);
            //Console.WriteLine(o);
            //Console.SetCursorPosition(0, 7);  //设置光标位置  列，行
            //Console.ReadLine();
            #endregion
            #region 循环检测文件更新
            //do
            //{
            //    string fn = "HuyaKV.txt";
            //    string json = "Huya.json";
            //    string strJson = File.ReadAllText(json);
            //    List<HuyaCookie> huyaCookies = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HuyaCookie>>(strJson);
            //    string str = File.ReadAllText(fn);
            //    bool flg = false;
            //    foreach (var item in str.Split(';'))
            //    {
            //        if (item.Contains("="))
            //        {
            //            string[] kv = item.Split('=');
            //            string k = kv[0];
            //            string v = string.Empty;
            //            if (kv.Length > 1)
            //            {
            //                v = kv[1];
            //            }
            //            foreach (var ck in huyaCookies)
            //            {
            //                if (ck.name == k)
            //                {
            //                    ck.value = v;
            //                    flg = true;
            //                }
            //            }
            //        }
            //    }
            //    string newJson = Newtonsoft.Json.JsonConvert.SerializeObject(huyaCookies);
            //    File.WriteAllText("New.Huya.json", newJson);
            //    Console.WriteLine($"状态:{flg};NewCookie：{newJson}");

            //    string reJson = File.ReadAllText("Re-Huya.json");

            //    List<HuyaCookie> ReHuyaCookies = Newtonsoft.Json.JsonConvert.DeserializeObject<List<HuyaCookie>>(reJson);
            //    foreach (var re in ReHuyaCookies)
            //    {
            //        foreach (var item in huyaCookies)
            //        {
            //            if (item.name == re.name)
            //            {
            //                if (item.value == re.value)
            //                {

            //                }
            //                else
            //                {
            //                    Console.WriteLine($"\r\n{item.name}={item.value};--->{re.name}={re.value};");
            //                }
            //            }
            //        }
            //    }
            //    Console.WriteLine("按任意键继续......");


            //    Console.ReadLine();
            //} while (true);
            #endregion
            #region 磁盘写入耗时测试
            //do
            //{
            //    string appTxt = $"{DateTime.Now}\r\n";
            //    Stopwatch sw = new Stopwatch();
            //    sw.Start();
            //    System.IO.File.AppendAllText("hellowrld.log", appTxt, System.Text.Encoding.UTF8);
            //    sw.Stop();
            //    Console.WriteLine($"Hello World:{DateTime.Now}!==>{appTxt.Length},耗时：{sw.ElapsedMilliseconds}");
            //    System.Threading.Thread.Sleep(1000);
            //} while (true);

            #endregion
        }
    }
}
